package com.xiaren.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ComponentEvent;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import javax.swing.plaf.basic.BasicBorders;

import com.xiaren.common.IConstant;
import com.xiaren.common.ObjectConstant;
import com.xiaren.ui.edit.EditAction;
import com.xiaren.ui.edit.MainEdit;
import com.xiaren.util.ColorComboBox;
import com.xiaren.util.FontSizeComboBox;
import com.xiaren.util.InetAddPassBtn;

/**
 * 中间一大块的那个面板
 *
 * @author xiaren
 * @主页 http://www.leaf123.cn/
 * @邮箱 xia5523@qq.com
 */
public class CenterJPanel extends JPanel implements ComResizedListener {

	public MainEdit mainEdit = new MainEdit(SwingConstants.TOP);
	JPanel toolBarPanel = new JPanel();// 用于放置toolbar
	public JToolBar toolBar = new JToolBar();

	public JScrollPane jsp = new JScrollPane();

	public CenterJPanel() {
		super();
	}

	void initCommpent() {
		this.setLayout(new BorderLayout());
		toolBar.setLayout(new FlowLayout());
		toolBar.add(ObjectConstant.btnBold = new JButton());
		toolBar.add(ObjectConstant.btnUnderLine = new JButton());
		toolBar.add(ObjectConstant.btnItalic = new JButton());
		toolBar.addSeparator();
		toolBar.add(new ColorComboBox());
		toolBar.add(new FontSizeComboBox());
//		toolBar.add(new InetAddPassBtn("192.168.1.102"));
		// toolBar.add(new JButton("parse"));
		// toolBar.add(new JButton("parse"));
		// toolBar.add(new JButton("parse"));
		// toolBar.add(new JButton("parse"));

		toolBar.setFloatable(false);
		toolBar.setBorder(BasicBorders.getMenuBarBorder());
		toolBarPanel.setLayout(new BorderLayout());
		toolBarPanel.add(toolBar, BorderLayout.WEST);
		this.add(toolBarPanel, BorderLayout.NORTH);
		this.add(mainEdit, BorderLayout.CENTER);

	}

	public void init() {
		initCommpent();
		mainEdit.init();

		// 给按钮添加监听
		EditAction.addBoldAtion(ObjectConstant.btnBold);
		EditAction.addUnderLineAtion(ObjectConstant.btnUnderLine);
		EditAction.addItalicAtion(ObjectConstant.btnItalic);

	}

	@Override
	public void resized(ComponentEvent e) {

		this.setBounds(IConstant.LEFTPANEL_WIDTH, IConstant.TOOLBAR_HEIGHT, e
				.getComponent().getWidth()
				- IConstant.LEFTPANEL_WIDTH, e.getComponent().getHeight()
				- IConstant.TOOLBAR_HEIGHT);
	}

}
